load("@fbcode//eden/scm:targets.bzl", "exec_compatible_with_target")
load("@fbcode_macros//build_defs:native_rules.bzl", "buck_genrule")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")

oncall("sapling")

buck_genrule(
    name = "gen=compiled.rs",
    out = "compiled.rs",
    # exe_target respects PACKAGE Python version override. exe does not.
    cmd = "$(exe_target //eden/scm/lib/python-modules/codegen-exe:codegen-exe) --out $OUT --sys-path $(location //eden/scm:pure-modules)",
    # Force execution platform to match target platform to avoid "exec format error".
    # See docstring of exec_compatible_with_target.
    exec_compatible_with = exec_compatible_with_target(),
)

rust_library(
    name = "python-modules",
    srcs = ["src/lib.rs"],
    autocargo = {"cargo_toml_config": {
        "extra_buck_dependencies": {
            "build-dependencies": [
                "//eden/scm/lib/python-modules/codegen:codegen",
            ],
        },
        "lib": {"name": "python-modules"},
        "package": {
            "authors": ["Meta Source Control Team <sourcecontrol-dev@meta.com>"],
            "homepage": "https://sapling-scm.com/",
            "license": "GPL-2.0-only",
            "name": "python-modules",
            "repository": "https://github.com/facebook/sapling",
        },
    }},
    mapped_srcs = {":gen=compiled.rs": "src/compiled.rs"},
    deps = [
        "fbsource//third-party/rust:once_cell",
        "fbsource//third-party/rust:phf",
        "//eden/scm/lib/zstdelta:zstdelta",
    ],
)
